home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / email / encoders.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  2KB  |  70 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. __all__ = [
  5.     'encode_7or8bit',
  6.     'encode_base64',
  7.     'encode_noop',
  8.     'encode_quopri']
  9. import base64
  10. from quopri import encodestring as _encodestring
  11.  
  12. def _qencode(s):
  13.     enc = _encodestring(s, quotetabs = True)
  14.     return enc.replace(' ', '=20')
  15.  
  16.  
  17. def _bencode(s):
  18.     if not s:
  19.         return s
  20.     
  21.     hasnewline = s[-1] == '\n'
  22.     value = base64.encodestring(s)
  23.     if not hasnewline and value[-1] == '\n':
  24.         return value[:-1]
  25.     
  26.     return value
  27.  
  28.  
  29. def encode_base64(msg):
  30.     orig = msg.get_payload()
  31.     encdata = _bencode(orig)
  32.     msg.set_payload(encdata)
  33.     msg['Content-Transfer-Encoding'] = 'base64'
  34.  
  35.  
  36. def encode_quopri(msg):
  37.     orig = msg.get_payload()
  38.     encdata = _qencode(orig)
  39.     msg.set_payload(encdata)
  40.     msg['Content-Transfer-Encoding'] = 'quoted-printable'
  41.  
  42.  
  43. def encode_7or8bit(msg):
  44.     orig = msg.get_payload()
  45.     if orig is None:
  46.         msg['Content-Transfer-Encoding'] = '7bit'
  47.         return None
  48.     
  49.     
  50.     try:
  51.         orig.encode('ascii')
  52.     except UnicodeError:
  53.         charset = msg.get_charset()
  54.         if charset:
  55.             pass
  56.         output_cset = charset.output_charset
  57.         if output_cset and output_cset.lower().startswith('iso-2202-'):
  58.             msg['Content-Transfer-Encoding'] = '7bit'
  59.         else:
  60.             msg['Content-Transfer-Encoding'] = '8bit'
  61.     except:
  62.         output_cset.lower().startswith('iso-2202-')
  63.  
  64.     msg['Content-Transfer-Encoding'] = '7bit'
  65.  
  66.  
  67. def encode_noop(msg):
  68.     pass
  69.  
  70.